#!/bin/bash

node_name=$1
node_ip=$2
join_token=$3

echo -e "\n\n=========== 安装nfs ================"
yum install -y rpcbind nfs-utils
mkdir /mnt/storage
chmod 777 -R /mnt
cat >>/etc/exports<<EOF
/mnt/storage *(rw,sync,no_root_squash,no_subtree_check)
EOF
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
exportfs -r

export INSTALL_K3S_MIRROR=cn
export IP=$node_ip
export INSTALL_K3S_EXEC="server --tls-san \"$IP\" --write-kubeconfig-mode 664 --node-ip \"$IP\" --node-external-ip \"$IP\" --advertise-address \"$IP\" --flannel-iface eth1 --node-name $node_name --node-label=flannel.alpha.coreos.com/public-ip-overwrite=\"$IP\" --token $join_token"

curl -sfL https://rancher-mirror.oss-cn-beijing.aliyuncs.com/k3s/k3s-install.sh | sh -

mkdir -p ~/.kube/
ln -s /etc/rancher/k3s/k3s.yaml ~/.kube/config

# 集权完全起来之后,验证node之间网络是否联通
# https://docs.ranchermanager.rancher.io/zh/troubleshooting/other-troubleshooting-tips/networking